package com.vgooo.client.tool.tester;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.os.Bundle;
import android.widget.TextView;

import com.umeng.analytics.MobclickAgent;
import com.vgooo.client.R;

public class TestHst extends BaseTestActivity {

	final static String KEY = "hst";

	BroadcastReceiver receiver;

	TextView textView;
	Context mContext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test_hst);

		init(KEY);

		mContext = this;

		textView = (TextView) findViewById(R.id.hst);
		/*
		 * String action = this.getIntent().getAction(); if
		 * (action.equals(Intent.ACTION_HEADSET_PLUG)) {
		 * if(this.getIntent().getIntExtra("state", 0) == 1){
		 * textView.setText(getResources().getText(R.string.txt_in_hst)); }else{
		 * textView.setText(getResources().getText(R.string.txt_out_hst)); } }
		 */

		receiver = new BroadcastReceiver() {

			@Override
			public void onReceive(Context context, Intent intent) {
				String action = intent.getAction();
				if (action.equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {

					if (intent.getStringExtra("state") == "1") {
						textView.setText(getResources().getText(
								R.string.txt_in_hst));
					} else {
						textView.setText(getResources().getText(
								R.string.txt_out_hst));
					}

				}
			}
		};
		registerReceiver(receiver, new IntentFilter(
				AudioManager.ACTION_AUDIO_BECOMING_NOISY));
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		// 友盟统计功能，打开页面
		MobclickAgent.onResume(this);
		super.onResume();
	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		// 友盟统计功能，页面关闭
		MobclickAgent.onPause(this);
		super.onPause();
	}
	
	
	@Override
	protected void onDestroy() {
		unregisterReceiver(receiver);
		super.onDestroy();
	}

}
